package controller

import (
	"fx_swift_schedule/internal/service"
	"fx_swift_schedule/pkg/code"
	"fx_swift_schedule/pkg/internalerrors"
	"fx_swift_schedule/pkg/logger"
	"github.com/gin-gonic/gin"
	"io/ioutil"
	"net/http"
)

func CardTransaction(c *gin.Context) {
	bodyContent, _ := ioutil.ReadAll(c.Request.Body)
	logger.SugarLogger.Info(string(bodyContent))
	err := service.NewCardCallBackSrv().CardTransaction(c, string(bodyContent))
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

func CardSettlementInfo(c *gin.Context) {
	startTime := c.Query("start_time")
	endTime := c.Query("end_time")
	err := service.NewCardCallBackSrv().CardSettlementInfo(c, startTime, endTime)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

func ManualSendCallBack(c *gin.Context) {
	err := service.NewCardCallBackSrv().ManualSendCallBack(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}

func ManualOperatorCardHeader(c *gin.Context) {
	err := service.NewCardCallBackSrv().ManualOperatorCardHeader(c)
	if err != nil {
		code.Fail(c, http.StatusBadRequest, err.(internalerrors.ServiceError).Code, err.(internalerrors.ServiceError).Msg)
		return
	} else {
		code.Success(c, nil)
	}
}
